package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniMoney;
import com.ruoyi.applet.service.IMiniMoneyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品型号对应的部位价目Controller
 *
 * @author liucan
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/applet/money")
public class MiniMoneyController extends BaseController {
    @Resource
    private IMiniMoneyService miniMoneyService;

    @Resource
    private MiniLeagueController miniLeagueController;

    /**
     * 查询产品型号对应的部位价目列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniMoney miniMoney, HttpServletRequest request) {
        startPage();
        miniMoney.setToApplet(miniLeagueController.toApplet(request));
        List<MiniMoney> list = miniMoneyService.selectMiniMoneyList(miniMoney);
        return getDataTable(list,null);
    }

    /**
     * 新增产品型号对应的部位价目
     */
    @Log(title = "产品型号对应的部位价目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniMoney miniMoney, HttpServletRequest request) {
        miniMoney.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniMoneyService.insertMiniMoney(miniMoney));
    }

    /**
     * 修改产品型号对应的部位价目
     */
    @Log(title = "产品型号对应的部位价目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniMoney miniMoney, HttpServletRequest request) {
        miniMoney.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniMoneyService.updateMiniMoney(miniMoney));
    }

    /**
     * 删除产品型号对应的部位价目
     */
    @Log(title = "产品型号对应的部位价目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniMoneyService.deleteMiniMoneyByIds(ids));
    }


    /**
     * 导出产品型号对应的部位价目列表
     */
    @Log(title = "产品型号对应的部位价目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniMoney miniMoney) {
        List<MiniMoney> list = miniMoneyService.selectMiniMoneyList(miniMoney);
        ExcelUtil<MiniMoney> util = new ExcelUtil<MiniMoney>(MiniMoney.class);
        util.exportExcel(response, list, "产品型号对应的部位价目数据");
    }

    /**
     * 获取产品型号对应的部位价目详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniMoneyService.selectMiniMoneyById(id));
    }

}
